Skip to content

feat(admin): create and delete alerts and reports on behalf of a user - #10232

Open
nishantmonu51 wants to merge 10 commits into
nishant/ai-alertsfrom
nishant/alerts-reports-for-user
Open

nishantmonu51 wants to merge 10 commits into
nishant/ai-alertsfrom
nishant/alerts-reports-for-user

Conversation

@nishantmonu51

Copy link
Copy Markdown
Collaborator

Takes over #10121, reduced to create and delete as its review asked. Stacked on #10231.

  • CreateAlertForUser, DeleteAlertForUser, CreateReportForUser and DeleteReportForUser let the runtime act for the user of its AI session. They write the same managed YAML as CreateAlert and CreateReport, through shared helpers.
  • Only the project's primary deployment can call them. It is trusted to pass its session's user, as for GetAlertMeta, GetReportMeta and GetConnectorOAuthToken. The trust-model decision for feat(ai): let the analyst create and edit the user's personal dashboards #10030 is still open; this follows whatever is decided there.
  • Confirmation enforced in code, the first option from the feat(ai): create, edit and list alerts from the chat (save_alert, list_alerts) #10122 review: recipients default to the user, other email and Slack-user recipients must be project members, and Slack channels and webhooks are rejected. What the AI creates can't send data outside the project.
  • Delete only deletes the user's own alerts and reports, even for users who can manage others'.
  • No list, edit, versions or YAML read-back: the runtime lists from its catalog. The runtime's AdminService takes adminv1.AlertOptions and adminv1.ReportOptions, so there's no third copy of the options.
  • The test runs a real runtime instance as the project's deployment, with the admin service as its admin connector, so creates and deletes go through the YAML, parser and reconcile path.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

nishantmonu51 and others added 4 commits November 28, 2026 12:16
Adds CreateAlertForUser, DeleteAlertForUser, CreateReportForUser and DeleteReportForUser,
and exposes them to the runtime through the admin service driver, for the AI tools that create alerts and reports from the chat.

- Only the project's primary deployment can call them, for a user of the project, as it does for GetAlertMeta, GetReportMeta and GetConnectorOAuthToken.
- They write the same managed YAML as CreateAlert and CreateReport, owned by the user, through shared helpers.
- What they create only reaches project members: recipients default to the user, other recipients must be members of the project, and Slack channels and webhooks are rejected.
- Delete only deletes the user's own alerts and reports, even for users who can manage others'.
- The runtime's AdminService takes the admin proto's AlertOptions and ReportOptions, instead of a copy of them.

Based on the reviewed design of #10121, which also listed and edited alerts and reports; editing from the chat is out of scope for now.

Co-authored-by: dfliess <dfliess@gmail.com>

@nishantmonu51 nishantmonu51 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of API details and a small cleanup inline.

Comment thread admin/server/for_user.go
if err != nil {
return nil, nil, err
}
return user, projPerms, nil

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we check projPerms.ReadProd here? The regular DeleteAlert and DeleteReport endpoints both check current production access before checking ownership. The new delete handlers only check ownership, so their behavior diverges after a user's project access is revoked.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8883105: userForPrimaryDeployment now rejects users without ReadProd, so all four RPCs, deletes included, match the regular endpoints; a new subtest covers a user removed from the project.

Comment thread admin/server/alerts.go Outdated
return nil, err
}

org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both create RPCs fetch the organization after writing and reconciling the resource. If that lookup fails, chat reports a failed create even though the alert or report exists. A retry uses a fresh name and can schedule duplicate notifications. Could we move FindOrganization above createManagedAlert and createManagedReport?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8883105: both create RPCs look up the organization before creating the alert or report.

Comment thread admin/server/for_user.go Outdated
return []string{user.Email}, nil
}

for _, recipient := range append(append([]string{}, emails...), slackUsers...) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use slices.Concat(emails, slackUsers) here? It gives the same iteration order and leaves the caller's slices alone without the nested appends.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8883105: uses slices.Concat(emails, slackUsers).

@pjain1

pjain1 commented Nov 29, 2026

Copy link
Copy Markdown
Member

This is the shape we wanted: four RPCs that share their helpers with CreateAlert and DeleteAlert, with the recipient rule enforced in the admin service. Two changes.

Allow Slack channels. "Alert me in #sales-ops" is a common request, and a channel sits inside the Slack workspace that the project's admin configured. Please let recipientsForUser accept Slack channels, and keep rejecting webhooks, since a webhook is an arbitrary URL.

The url response field is redundant. CreateAlertForUserResponse.url and CreateReportForUserResponse.url duplicate what resourcePageURL in #10233 already builds in the runtime from the instance's frontend URL. Dropping the field also removes the organization lookup in both handlers.


Developed in collaboration with Claude Code

… and drop the url response field after review

- recipientsForUser allows Slack channels, which are in the workspace the project's admin configured, and still rejects webhooks. The user's email is only the default when there are no recipients at all.
- CreateAlertForUserResponse and CreateReportForUserResponse no longer return a url, so the handlers skip the organization lookup; the runtime builds the page URL from the instance's frontend URL.
@nishantmonu51

Copy link
Copy Markdown
Collaborator Author

@pjain1 Thanks, both done in b6c94e0 (after merging #10231 in 2459b49):

@nishantmonu51 nishantmonu51 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things on Slack delivery.

Comment thread admin/server/for_user.go
// Slack channels are allowed, since they're in the Slack workspace the project's admin configured,
// and Slack webhooks, which can be any URL, are rejected.
func (s *Server) recipientsForUser(ctx context.Context, proj *database.Project, user *database.User, emails, slackUsers, slackChannels, slackWebhooks []string) ([]string, error) {
if len(slackWebhooks) > 0 {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can recipientsForUser require a verified internal Slack channel here? sendTextToChannels passes the destination straight to chat.postMessage, which also accepts DM destinations, and Slack Connect channels can have readers outside the workspace. That can send an alert’s rows or a report’s summary beyond the intended audience. Resolve the destination to a channel ID and check its conversation type and external-sharing status before accepting it. Posting destinations · Slack Connect channel flags

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly fixed in 7f91a46: @name and user or DM IDs (U/W/D) are now rejected as channels, so people are only reached as Slack users who are project members; ruling out Slack Connect channels needs a conversations.info call with the project's Slack token, which only the runtime has, so I've left that for a decision (the regular create endpoints and the form don't check channels either).

Comment thread admin/server/for_user.go
if len(slackWebhooks) > 0 {
return nil, status.Error(codes.InvalidArgument, "the AI can't send to Slack webhooks, since they can be any URL")
}
if len(emails) == 0 && len(slackUsers) == 0 && len(slackChannels) == 0 {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Slack-only alert or report can now be created in a project with no Slack setup, with no email fallback. The user gets a success response and delivery fails later in sendTextToChannels. Could the for-user create path check notifier availability before saving and tell the user to configure Slack or choose email? The web form already checks ListNotifierConnectors in FormMetadataProvider.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this to the chat tools in #10233 and #10234: the admin service can't see whether the instance has a Slack connector (it can come from project files or variables), so they will check it like the form's ListNotifierConnectors before calling this RPC.

…a user after review

chat.postMessage also takes "@name" and user or direct message IDs as a channel, which would reach people who aren't members of the project.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area:AI AI assistant, chat and agents Area:Alerts Size:L Large change: 500-1,999 lines Type:Feature New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants